//参数校验 错误处理中间件
const { validationResult} = require('express-validator');

//接收校验promise错误数组
//返回检验报错信息数组
module.exports = validators => {
    return async (req,res,next)=>{
      await Promise.all(validators.map(validator=>validator.run(req)))
      const errors = validationResult(req);
      if(!errors.isEmpty()){
        return  res.status(400).json({errors:errors.array().reverse()})
      }
      next()
    }
}